<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Purchase extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->check();
        $this->load->helper('url');
        $this->load->model('admin/admin_m');
        $this->load->model('admin/purchase_m');
    }
    
    public function check(){
        $this->id = $this->session->userdata('user_id');
        if(empty($this->id)){
            redirect('admin/user/login');
        }
    }
    
    public function index(){
        $data['active'] = 4;
        $data['breadcumb'] = $this->admin_m->get_breadcumb(array('Purchase'=>'purchase','List'=>'purchase'));
        $data['purchase'] = $this->purchase_m->get_purchase();
        $data['page'] = 1;
        $data['count'] = $this->purchase_m->get_purchase_count();
        $data['start'] = 0;
        $data['content'] = $this->load->view('admin/purchase/list_v',$data,TRUE);
        $this->load->view('admin/admin_v',$data);
    }
    
    public function add(){
        $data['active'] = 4;
        $data['breadcumb'] = $this->admin_m->get_breadcumb(array('purchase'=>'purchase','List'=>'purchase','Add'=>'purchase/add'));
        $data['content'] = $this->load->view('admin/purchase/add_v',$data,TRUE);
        $this->load->view('admin/admin_v',$data);
    }
    
    public function view($id){
        $data['active'] = 4;
        $data['breadcumb'] = $this->admin_m->get_breadcumb(array('purchase'=>'purchase','List'=>'purchase','View'=>'purchase/view'));
        $data['purchase'] = $this->purchase_m->get_purchase(0,$id)->first_row();
        $data['purchase_item'] = $this->purchase_m->get_purchase_item($id);
        $data['content'] = $this->load->view('admin/purchase/view_v',$data,TRUE);
        $this->load->view('admin/admin_v',$data);
    }
    
    
    public function delete($id){
        $this->purchase_m->delete($id);
        $this->session->set_flashdata('f_purchase','purchase has been deleted');
        redirect('admin/purchase');
    }
}

?>